﻿IF EXISTS (
    SELECT
      1
    FROM sysobjects
    WHERE id = OBJECT_ID('bd_proc_schedule_group_delete')
      AND type IN ('P', 'PC')
  )
  DROP PROCEDURE bd_proc_schedule_group_delete

GO

-- =============================================
-- Author:      YFC
-- Create date: 2020-07-17 22:43:43
-- Database:    [scm_main-hysj2]
-- Description: 排班管理-班组删除
-- =============================================

CREATE PROCEDURE bd_proc_schedule_group_delete
(
  @groupIds VARCHAR(MAX)
)
AS
BEGIN
  SET NOCOUNT ON;

  BEGIN TRY
    BEGIN TRANSACTION

      DECLARE @sql VARCHAR(MAX) = ''

      SELECT @sql = '
        DELETE FROM bd_schedule_group_employee WHERE group_id IN (' + @groupIds + ') '
      EXEC(@sql)

      SELECT @sql = '
        DELETE FROM bd_schedule_group WHERE id IN (' + @groupIds + ') '
      EXEC(@sql)

      SELECT @@rowcount

    COMMIT TRANSACTION
  END TRY
  BEGIN CATCH
    DECLARE @errStr VARCHAR(MAX) = ERROR_MESSAGE();

    IF XACT_STATE() <> 0
    BEGIN
      ROLLBACK TRANSACTION;
    END;
    RAISERROR (@errStr, 16, 1);
  END CATCH;


  SET NOCOUNT OFF;
END
GO
